package com.ck.ips.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 异步设置
 *
 * @author linqiang
 * @date 2018-07-18 11:07
 */
@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean
    public Executor taskExecutor(CustomProperties customProperties) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(customProperties.getAsyncCorePoolSize());
        executor.setMaxPoolSize(customProperties.getAsyncMaxPoolSize());
        executor.setQueueCapacity(customProperties.getAsyncQueuePoolSize());
        executor.initialize();
        return executor;
    }
}
